{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Importing packages\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import sklearn\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "from sklearn import preprocessing\n",
    "import statsmodels.api as sm\n",
    "import seaborn as sns; sns.set(color_codes=True)\n",
    "import math\n",
    "import pickle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Parameters\n",
    "\n",
    "v=10\n",
    "lam=.125\n",
    "mu=100000\n",
    "c=1\n",
    "\n",
    "start=1\n",
    "end=1001\n",
    "inc=float(1)/(end-start)\n",
    "\n",
    "endow=10\n",
    "\n",
    "def risk(value,r):\n",
    "    return (value**(1-r))/(1-r)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Period Functions**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def period10(piold):\n",
    "    draws=[[],[],[],[],[],[],[],[],[],[]]\n",
    "    payoffs=[[],[],[],[],[],[],[],[],[],[]]\n",
    "\n",
    "    for x in range(0,10):\n",
    "        for i in range(1001):\n",
    "            vDraw=((risk(endow+v-c*(x+1),r))*(piold[i]*(.001*i)+sum([(.001)*piold[j] for j in range(i+1,1001)])))+(((risk(endow-c*(x+1),r)))*(1-(piold[i]*(.001*i)+sum([(.001)*piold[j] for j in range(i+1,1001)]))))\n",
    "            vNoDraw=((risk(endow+v-c*x,r))*piold[i])+((risk(endow-c*x,r))*(1-piold[i]))\n",
    "            probDraw=np.exp(mu*(vDraw-max(vDraw,vNoDraw)))/(np.exp(mu*(vDraw-max(vDraw,vNoDraw)))+np.exp(mu*(vNoDraw-max(vDraw,vNoDraw))))\n",
    "            draws[x].append(probDraw)\n",
    "            payoffs[x].append(vDraw*(probDraw)+vNoDraw*(1-probDraw))\n",
    "            \n",
    "    return [draws,payoffs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def period9(piold,payoffs10):\n",
    "    draws=[[],[],[],[],[],[],[],[],[]]\n",
    "    payoffs=[[],[],[],[],[],[],[],[],[]]\n",
    "\n",
    "    for x in range(0,9):\n",
    "        for i in range(1001):\n",
    "            vDraw=payoffs10[x+1][i]*(.001*i)+sum([(.001)*payoffs10[x+1][j] for j in range(i+1,1001)])\n",
    "            vNoDraw=payoffs10[x][i]\n",
    "            probDraw=np.exp(mu*(vDraw-max(vDraw,vNoDraw)))/(np.exp(mu*(vDraw-max(vDraw,vNoDraw)))+np.exp(mu*(vNoDraw-max(vDraw,vNoDraw))))\n",
    "            draws[x].append(probDraw)\n",
    "            payoffs[x].append(vDraw*(probDraw)+vNoDraw*(1-probDraw))  \n",
    "\n",
    "    \n",
    "    return [draws,payoffs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def period8(piold,payoffs9):\n",
    "    draws=[[],[],[],[],[],[],[],[]]\n",
    "    payoffs=[[],[],[],[],[],[],[],[]]\n",
    "\n",
    "    for x in range(0,8):\n",
    "        for i in range(1001):\n",
    "            vDraw=payoffs9[x+1][i]*(.001*i)+sum([(.001)*payoffs9[x+1][j] for j in range(i+1,1001)])\n",
    "            vNoDraw=payoffs9[x][i]\n",
    "            probDraw=np.exp(mu*(vDraw-max(vDraw,vNoDraw)))/(np.exp(mu*(vDraw-max(vDraw,vNoDraw)))+np.exp(mu*(vNoDraw-max(vDraw,vNoDraw))))\n",
    "            draws[x].append(probDraw)\n",
    "            payoffs[x].append(vDraw*(probDraw)+vNoDraw*(1-probDraw))  \n",
    "\n",
    "    \n",
    "    return [draws,payoffs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def period7(piold,payoffs8):\n",
    "    draws=[[],[],[],[],[],[],[]]\n",
    "    payoffs=[[],[],[],[],[],[],[]]\n",
    "\n",
    "    for x in range(0,7):\n",
    "        for i in range(1001):\n",
    "            vDraw=payoffs8[x+1][i]*(.001*i)+sum([(.001)*payoffs8[x+1][j] for j in range(i+1,1001)])\n",
    "            vNoDraw=payoffs8[x][i]\n",
    "            probDraw=np.exp(mu*(vDraw-max(vDraw,vNoDraw)))/(np.exp(mu*(vDraw-max(vDraw,vNoDraw)))+np.exp(mu*(vNoDraw-max(vDraw,vNoDraw))))\n",
    "            draws[x].append(probDraw)\n",
    "            payoffs[x].append(vDraw*(probDraw)+vNoDraw*(1-probDraw))  \n",
    "\n",
    "    \n",
    "    return [draws,payoffs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def period6(piold,payoffs7):\n",
    "    draws=[[],[],[],[],[],[]]\n",
    "    payoffs=[[],[],[],[],[],[]]\n",
    "\n",
    "    for x in range(0,6):\n",
    "        for i in range(1001):\n",
    "            vDraw=payoffs7[x+1][i]*(.001*i)+sum([(.001)*payoffs7[x+1][j] for j in range(i+1,1001)])\n",
    "            vNoDraw=payoffs7[x][i]\n",
    "            probDraw=np.exp(mu*(vDraw-max(vDraw,vNoDraw)))/(np.exp(mu*(vDraw-max(vDraw,vNoDraw)))+np.exp(mu*(vNoDraw-max(vDraw,vNoDraw))))\n",
    "            draws[x].append(probDraw)\n",
    "            payoffs[x].append(vDraw*(probDraw)+vNoDraw*(1-probDraw))  \n",
    "\n",
    "    \n",
    "    return [draws,payoffs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def period5(piold,payoffs6):\n",
    "    draws=[[],[],[],[],[]]\n",
    "    payoffs=[[],[],[],[],[]]\n",
    "\n",
    "    for x in range(0,5):\n",
    "        for i in range(1001):\n",
    "            vDraw=payoffs6[x+1][i]*(.001*i)+sum([(.001)*payoffs6[x+1][j] for j in range(i+1,1001)])\n",
    "            vNoDraw=payoffs6[x][i]\n",
    "            probDraw=np.exp(mu*(vDraw-max(vDraw,vNoDraw)))/(np.exp(mu*(vDraw-max(vDraw,vNoDraw)))+np.exp(mu*(vNoDraw-max(vDraw,vNoDraw))))\n",
    "            draws[x].append(probDraw)\n",
    "            payoffs[x].append(vDraw*(probDraw)+vNoDraw*(1-probDraw))  \n",
    "\n",
    "    \n",
    "    return [draws,payoffs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def period4(piold,payoffs5):\n",
    "    draws=[[],[],[],[]]\n",
    "    payoffs=[[],[],[],[]]\n",
    "\n",
    "    for x in range(0,4):\n",
    "        for i in range(1001):\n",
    "            vDraw=payoffs5[x+1][i]*(.001*i)+sum([(.001)*payoffs5[x+1][j] for j in range(i+1,1001)])\n",
    "            vNoDraw=payoffs5[x][i]\n",
    "            probDraw=np.exp(mu*(vDraw-max(vDraw,vNoDraw)))/(np.exp(mu*(vDraw-max(vDraw,vNoDraw)))+np.exp(mu*(vNoDraw-max(vDraw,vNoDraw))))\n",
    "            draws[x].append(probDraw)\n",
    "            payoffs[x].append(vDraw*(probDraw)+vNoDraw*(1-probDraw))  \n",
    "\n",
    "    \n",
    "    return [draws,payoffs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def period3(piold,payoffs4):\n",
    "    draws=[[],[],[]]\n",
    "    payoffs=[[],[],[]]\n",
    "\n",
    "    for x in range(0,3):\n",
    "        for i in range(1001):\n",
    "            vDraw=payoffs4[x+1][i]*(.001*i)+sum([(.001)*payoffs4[x+1][j] for j in range(i+1,1001)])\n",
    "            vNoDraw=payoffs4[x][i]\n",
    "            probDraw=np.exp(mu*(vDraw-max(vDraw,vNoDraw)))/(np.exp(mu*(vDraw-max(vDraw,vNoDraw)))+np.exp(mu*(vNoDraw-max(vDraw,vNoDraw))))\n",
    "            draws[x].append(probDraw)\n",
    "            payoffs[x].append(vDraw*(probDraw)+vNoDraw*(1-probDraw))  \n",
    "\n",
    "    \n",
    "    return [draws,payoffs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def period2(piold,payoffs3):\n",
    "    draws=[[],[]]\n",
    "    payoffs=[[],[]]\n",
    "\n",
    "    for x in range(0,2):\n",
    "        for i in range(1001):\n",
    "            vDraw=payoffs3[x+1][i]*(.001*i)+sum([(.001)*payoffs3[x+1][j] for j in range(i+1,1001)])\n",
    "            vNoDraw=payoffs3[x][i]\n",
    "            probDraw=np.exp(mu*(vDraw-max(vDraw,vNoDraw)))/(np.exp(mu*(vDraw-max(vDraw,vNoDraw)))+np.exp(mu*(vNoDraw-max(vDraw,vNoDraw))))\n",
    "            draws[x].append(probDraw)\n",
    "            payoffs[x].append(vDraw*(probDraw)+vNoDraw*(1-probDraw))  \n",
    "\n",
    "    \n",
    "    return [draws,payoffs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def period1(piold,payoffs2):\n",
    "    draws=[[]]\n",
    "    payoffs=[[]]\n",
    "\n",
    "    x=0\n",
    "    i=0\n",
    "    vDraw=payoffs2[x+1][i]*(.001*i)+sum([(.001)*payoffs2[x+1][j] for j in range(i+1,1001)])\n",
    "    vNoDraw=payoffs2[x][i]\n",
    "    probDraw=np.exp(mu*(vDraw-max(vDraw,vNoDraw)))/(np.exp(mu*(vDraw-max(vDraw,vNoDraw)))+np.exp(mu*(vNoDraw-max(vDraw,vNoDraw))))\n",
    "    draws[x].append(probDraw)\n",
    "    payoffs[x].append(vDraw*(probDraw)+vNoDraw*(1-probDraw))  \n",
    "\n",
    "    \n",
    "    return [draws,payoffs]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Estimation**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "def Estimation():\n",
    "    piold=[0 for i in range(1001)]\n",
    "    pinew=[.001*i for i in range(1001)]\n",
    "\n",
    "    while abs(sum(piold)-sum(pinew))>.25:\n",
    "\n",
    "        piold=pinew\n",
    "\n",
    "\n",
    "        [draws10,payoffs10]=period10(piold)\n",
    "        [draws9,payoffs9]=period9(piold,payoffs10)\n",
    "        [draws8,payoffs8]=period8(piold,payoffs9)\n",
    "        [draws7,payoffs7]=period7(piold,payoffs8)\n",
    "        [draws6,payoffs6]=period6(piold,payoffs7)\n",
    "        [draws5,payoffs5]=period5(piold,payoffs6)\n",
    "        [draws4,payoffs4]=period4(piold,payoffs5)\n",
    "        [draws3,payoffs3]=period3(piold,payoffs4)\n",
    "        [draws2,payoffs2]=period2(piold,payoffs3)\n",
    "        [draws1,payoffs1]=period1(piold,payoffs2)\n",
    "\n",
    "\n",
    "        scores=[]\n",
    "        for i in range(10000):\n",
    "            score1=0        \n",
    "            draws=0\n",
    "\n",
    "            for j in range(10):\n",
    "\n",
    "                FS1=int(math.ceil((1-np.exp(-.125*score1))*1000))\n",
    "\n",
    "                if j==0:\n",
    "                    drawP1=np.random.choice([0,1],size=1,p=[1-draws1[draws][FS1],draws1[draws][FS1]])\n",
    "                elif j==1:\n",
    "                    drawP1=np.random.choice([0,1],size=1,p=[1-draws2[draws][FS1],draws2[draws][FS1]])\n",
    "                elif j==2:\n",
    "                    drawP1=np.random.choice([0,1],size=1,p=[1-draws3[draws][FS1],draws3[draws][FS1]])\n",
    "                elif j==3:\n",
    "                    drawP1=np.random.choice([0,1],size=1,p=[1-draws4[draws][FS1],draws4[draws][FS1]])\n",
    "                elif j==4:\n",
    "                    drawP1=np.random.choice([0,1],size=1,p=[1-draws5[draws][FS1],draws5[draws][FS1]])\n",
    "                elif j==5:\n",
    "                    drawP1=np.random.choice([0,1],size=1,p=[1-draws6[draws][FS1],draws6[draws][FS1]])\n",
    "                elif j==6:\n",
    "                    drawP1=np.random.choice([0,1],size=1,p=[1-draws7[draws][FS1],draws7[draws][FS1]])\n",
    "                elif j==7:\n",
    "                    drawP1=np.random.choice([0,1],size=1,p=[1-draws8[draws][FS1],draws8[draws][FS1]])\n",
    "                elif j==8:\n",
    "                    drawP1=np.random.choice([0,1],size=1,p=[1-draws9[draws][FS1],draws9[draws][FS1]])\n",
    "                elif j==9:\n",
    "                    drawP1=np.random.choice([0,1],size=1,p=[1-draws10[draws][FS1],draws10[draws][FS1]])\n",
    "\n",
    "                if drawP1==1:\n",
    "                    score1=max(score1,np.random.exponential(8))\n",
    "                    draws=draws+1\n",
    "\n",
    "            scores.append(score1)\n",
    "\n",
    "        scores=np.array(scores)\n",
    "\n",
    "        pinew=[]\n",
    "        # calculate the proportional values of samples\n",
    "        for i in range(1000):\n",
    "            pinew.append((len(scores[scores<(-np.log(1-.001*i)/.125)])/len(scores)))\n",
    "        pinew.append(1)\n",
    "        print(abs(sum(piold)-sum(pinew)))\n",
    "        \n",
    "    return [draws1,draws2,draws3,draws4,draws5,draws6,draws7,draws8,draws9,draws10]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Simulation**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Simulation(draws1,draws2,draws3,draws4,draws5,draws6,draws7,draws8,draws9,draws10):\n",
    "    contest_draws=[]\n",
    "    for i in range(100000):\n",
    "        score1=0\n",
    "        score2=0\n",
    "        drawsFirst=0\n",
    "        drawsSecond=0\n",
    "\n",
    "        for j in range(10):\n",
    "\n",
    "            FS1=int(math.ceil((1-np.exp(-.125*score1))*1000))\n",
    "            FS2=int(math.ceil((1-np.exp(-.125*score2))*1000))\n",
    "\n",
    "\n",
    "            if j==0:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws1[drawsFirst][FS1],draws1[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws1[drawsSecond][FS2],draws1[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==1:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws2[drawsFirst][FS1],draws2[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws2[drawsSecond][FS2],draws2[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==2:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws3[drawsFirst][FS1],draws3[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws3[drawsSecond][FS2],draws3[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==3:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws4[drawsFirst][FS1],draws4[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws4[drawsSecond][FS2],draws4[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==4:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws5[drawsFirst][FS1],draws5[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws5[drawsSecond][FS2],draws5[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==5:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws6[drawsFirst][FS1],draws6[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws6[drawsSecond][FS2],draws6[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==6:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws7[drawsFirst][FS1],draws7[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws7[drawsSecond][FS2],draws7[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==7:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws8[drawsFirst][FS1],draws8[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws8[drawsSecond][FS2],draws8[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==8:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws9[drawsFirst][FS1],draws9[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws9[drawsSecond][FS2],draws9[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==9:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws10[drawsFirst][FS1],draws10[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws10[drawsSecond][FS2],draws10[drawsSecond][FS2]])\n",
    "\n",
    "            if drawP1==1:\n",
    "                score1=max(score1,np.random.exponential(8))\n",
    "                drawsFirst=drawsFirst+1\n",
    "            if drawP2==1:\n",
    "                score2=max(score2,np.random.exponential(8))\n",
    "                drawsSecond=drawsSecond+1\n",
    "\n",
    "        contest_draws.append(drawsFirst+drawsSecond)\n",
    "\n",
    "    return np.array(contest_draws).mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "draws_per_r=[]\n",
    "FinalProbsF=[]\n",
    "FinalProbsL=[]\n",
    "for r in [i*.05 for i in range(20)]:\n",
    "    [draws1,draws2,draws3,draws4,draws5,draws6,draws7,draws8,draws9,draws10]=Estimation()\n",
    "    average_draws=Simulation(draws1,draws2,draws3,draws4,draws5,draws6,draws7,draws8,draws9,draws10)\n",
    "    print(r,average_draws)\n",
    "    draws_per_r.append(average_draws)\n",
    "    FinalProbsF.append([draws1,draws2,draws3,draws4,draws5,draws6,draws7,draws8,draws9,draws10])\n",
    "    FinalProbsL.append([draws1,draws2,draws3,draws4,draws5,draws6,draws7,draws8,draws9,draws10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('Private_Risk.pkl', 'wb') as f:\n",
    "    pickle.dump(draws_per_r, f)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Simulation For Each Factor**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Private_Risk_Data=pd.DataFrame(columns=[\"Simulation Number\",\"Factor\",\"Coefficient Value\",\"Number of Draws\",\"Treatment\"])\n",
    "\n",
    "N=2\n",
    "T=10\n",
    "\n",
    "location=0\n",
    "for risk in range(19):\n",
    "    \n",
    "    [draws1,draws2,draws3,draws4,draws5,draws6,draws7,draws8,draws9,draws10]=FinalProbsF[risk]\n",
    "            \n",
    "    for i in range(10000):\n",
    "        score1=0\n",
    "        score2=0\n",
    "        drawsFirst=0\n",
    "        drawsSecond=0\n",
    "\n",
    "        for j in range(10):\n",
    "\n",
    "            FS1=int(math.ceil((1-np.exp(-.125*score1))*1000))\n",
    "            FS2=int(math.ceil((1-np.exp(-.125*score2))*1000))\n",
    "\n",
    "\n",
    "            if j==0:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws1[drawsFirst][FS1],draws1[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws1[drawsSecond][FS2],draws1[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==1:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws2[drawsFirst][FS1],draws2[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws2[drawsSecond][FS2],draws2[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==2:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws3[drawsFirst][FS1],draws3[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws3[drawsSecond][FS2],draws3[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==3:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws4[drawsFirst][FS1],draws4[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws4[drawsSecond][FS2],draws4[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==4:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws5[drawsFirst][FS1],draws5[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws5[drawsSecond][FS2],draws5[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==5:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws6[drawsFirst][FS1],draws6[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws6[drawsSecond][FS2],draws6[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==6:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws7[drawsFirst][FS1],draws7[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws7[drawsSecond][FS2],draws7[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==7:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws8[drawsFirst][FS1],draws8[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws8[drawsSecond][FS2],draws8[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==8:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws9[drawsFirst][FS1],draws9[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws9[drawsSecond][FS2],draws9[drawsSecond][FS2]])\n",
    "\n",
    "            elif j==9:\n",
    "                drawP1=np.random.choice([0,1],size=1,p=[1-draws10[drawsFirst][FS1],draws10[drawsFirst][FS1]])\n",
    "                drawP2=np.random.choice([0,1],size=1,p=[1-draws10[drawsSecond][FS2],draws10[drawsSecond][FS2]])\n",
    "\n",
    "            if drawP1==1:\n",
    "                score1=max(score1,np.random.exponential(8))\n",
    "                drawsFirst=drawsFirst+1\n",
    "            if drawP2==1:\n",
    "                score2=max(score2,np.random.exponential(8))\n",
    "                drawsSecond=drawsSecond+1\n",
    "\n",
    "\n",
    "        Private_Risk_Data.loc[location]=[iter,\"CRRA Coefficient\",.05*risk,drawsFirst+drawsSecond,\"Private\"]\n",
    "        location=location+1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Private_Risk_Data.to_csv(\"Private_Risk_Data.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
